/**
 * Copyright (c) 2017,安徽皖通科技股份有限公司 All rights reserved.
 * @data:2017年10月18日
 * @author:MaShibo
 */
package com.wttech.dzzf.process.dao;

import java.util.List;

import javax.annotation.Resource;

import cn.com.taiji.sdk.model.comm.protocol.transaction.ReimburseUploadRequest;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.wtkj.dao.impl.BaseDataTemplate;
import com.wtkj.dao.impl.ListResultSetExtractor;
import com.wttech.dzzf.process.model.transaction.ReimburseDTO;

/**
 * @date 2017年10月18日
 * @author MaShibo
 */
@Repository
public class ReimburseInfosDao extends BaseDataTemplate {
    
    
    @Resource(name = "dzzfJdbcTemplate")
    private JdbcTemplate dzzfJdbcTemplate;
    
    @Resource(name = "jdbcTemplate")
    private JdbcTemplate testJdbcTemplate;
    
    @SuppressWarnings("unchecked")
    public List<ReimburseDTO> queryReimburseInfos() {
        StringBuilder sql = new StringBuilder();
        sql.append(" SELECT T.CLIENTNO, T.ECARDNO, T.CARDNETID, A.REFUNDON, A.REFUNDMNY AS FEE ");
        sql.append("   FROM AC_CLCARD_REFINFO A ");
        sql.append("   JOIN AC_CARDINFOOPT T ");
        sql.append("     ON A.TRADENO = T.TRADENO ");
        sql.append("  WHERE A.STATE = 2 ");
        sql.append("    AND A.REFUNDON >= TO_DATE('20170101', 'yyyyMMdd') ");
        sql.append("    AND A.REFUNDON < TO_DATE('20171101', 'yyyyMMdd') ");
        return (List<ReimburseDTO>) dzzfJdbcTemplate.query(sql.toString(),
                new ListResultSetExtractor(new ReimburseDTO()));
    }
    
    public String queryUserIdByCardId(String cardId){
        return testJdbcTemplate.queryForObject("SELECT USERID FROM BS_CARD WHERE ID=? ", String.class, cardId);
    }

    public String queryUserIdByCardInfoId(String cardInfoId){
        return testJdbcTemplate.queryForObject("SELECT USERID FROM BS_USERCARD WHERE CARDINFOID=? ", String.class, cardInfoId);
    }

    public List<ReimburseUploadRequest> queryReimburseUploadInfos(){
        final String sql = "SELECT * FROM BS_REIMBURSE";
        return testJdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(ReimburseUploadRequest.class));
    }

}
